package com.xkcyy.one.controller;

import com.xkcyy.one.common.Result;
import com.xkcyy.one.entity.TrainingExample;
import com.xkcyy.one.service.TrainingExampleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 训练样例控制器
 */
@RestController
@RequestMapping("/api/training/examples")
public class TrainingExampleController {
    
    private final TrainingExampleService trainingExampleService;
    
    @Autowired
    public TrainingExampleController(TrainingExampleService trainingExampleService) {
        this.trainingExampleService = trainingExampleService;
    }
    
    /**
     * 根据训练ID获取样例列表
     *
     * @param trainingId 训练ID
     * @return 样例列表
     */
    @GetMapping("/training")
    public Result<List<TrainingExample>> getExamplesByTrainingId(@RequestParam Long trainingId) {
        return Result.success(trainingExampleService.getExamplesByTrainingId(trainingId));
    }
    
    /**
     * 根据ID获取样例
     *
     * @param id 样例ID
     * @return 样例信息
     */
    @GetMapping("/get")
    public Result<TrainingExample> getExampleById(@RequestParam Long id) {
        return Result.success(trainingExampleService.getExampleById(id));
    }
    
    /**
     * 创建样例
     *
     * @param example 样例信息
     * @return 创建后的样例信息
     */
    @PostMapping("/create")
    public Result<TrainingExample> createExample(@RequestBody TrainingExample example) {
        return Result.success(trainingExampleService.createExample(example));
    }
    
    /**
     * 批量创建样例
     *
     * @param examples 样例列表
     * @return 创建后的样例列表
     */
    @PostMapping("/batch")
    public Result<List<TrainingExample>> createExampleBatch(@RequestBody List<TrainingExample> examples) {
        return Result.success(trainingExampleService.createExampleBatch(examples));
    }
    
    /**
     * 更新样例
     *
     * @param id      样例ID
     * @param example 样例信息
     * @return 更新后的样例信息
     */
    @PutMapping("/update")
    public Result<TrainingExample> updateExample(@RequestParam Long id, @RequestBody TrainingExample example) {
        example.setId(id);
        return Result.success(trainingExampleService.updateExample(example));
    }
    
    /**
     * 删除样例
     *
     * @param id 样例ID
     * @return 操作结果
     */
    @DeleteMapping("/delete")
    public Result<Void> deleteExample(@RequestParam Long id) {
        trainingExampleService.deleteExample(id);
        return Result.success();
    }
} 